#include "Blade.h"

#include "../CommandManager.h"

#include "../Commands/UseBlade.h"

#include <algorithm>

Blade::Blade()
	: Component("Blade")
{
	auto cut = add<Cut>(CommandManager::getSingleton()->getCommand("cut"));
	auto stab = add<Stab>(CommandManager::getSingleton()->getCommand("stab"));
}

Blade::~Blade()
{
}

void Blade::registerCutAirCallback(std::function<void(const CharacterPtr &, const RoomPtr &)> &&callback)
{
	cutAirCallbacks.push_back(callback);
}

void Blade::cutAir(const CharacterPtr &character, const RoomPtr &room)
{
	std::for_each(begin(cutAirCallbacks), end(cutAirCallbacks), [&](const std::function<void(const CharacterPtr &, const RoomPtr &)> &callback)
	{
		callback(character, room);
	});
}

void Blade::registerCutTargetCallback(std::function<void(const CharacterPtr &, const CharacterPtr &, const RoomPtr &)> &&callback)
{
	cutTargetCallbacks.push_back(callback);
}

void Blade::cutTarget(const CharacterPtr &character, const CharacterPtr &target, const RoomPtr &room)
{
	std::for_each(begin(cutTargetCallbacks), end(cutTargetCallbacks), [&](const std::function<void(const CharacterPtr &, const CharacterPtr &, const RoomPtr &)> &callback)
	{
		callback(character, target, room);
	});
}
